<?php

namespace App\Http\Controllers\web;

use App\Http\Controllers\Controller;
use App\Service\product\ProductApiService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use lxs\api\ApiResponse;

class ProductController extends Controller
{

    /**
     * 获取广场列表页面数据
     */
    public function getSquareListData(Request $request): JsonResponse
    {

        $online_platform = $request->input('online_platform') ?? 1;
        $type = $request->input('type') ?? 0;

        $result = ProductApiService::instance()->getProductSquareDataWeb($online_platform, $type);
        if ($result['code'] != 200) {
            return ApiResponse::apiResponseData(4004, '获取产品广场页面数据失败');
        }

        $data = $result['data'];

        return ApiResponse::apiResponseData(200, '获取产品广场页面数据成功', $data);

    }


    /**
     * 获取广场产品介绍数据
     */
    public function getSquareIntroduceData(Request $request): JsonResponse
    {

        $uid = $request->web_uid;
        $id = $request->input('product_id');
        $popularize_id = $request->input('popularize_id');

        $result = ProductApiService::instance()->getProductDetailData($id, $popularize_id, $uid);
        if ($result['code'] != 200) {
            return ApiResponse::apiResponseData($result['code'], $result['message']);
        }

        return ApiResponse::apiResponseData(200, '获取广场产品介绍数据成功', $result['data']);
    }


}
